package haierhome.krund.cn.daggertworetrofitrxjavamvp.rxjava.exampletwo.net;

import haierhome.krund.cn.daggertworetrofitrxjavamvp.retrofit.bean.UserLogin;
import haierhome.krund.cn.daggertworetrofitrxjavamvp.rxjava.exampletwo.custom.CustomGsonConverterFactory;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Created by Administrator on 2018/8/14.
 */

public interface ApiService {

    /**
     * @param uesrname     post方法提交参数用 Field
     * @param password     post方法提交参数用 Field
     * @return
     */
    //post第一种请求方式
    @FormUrlEncoded  //这种是表单请求 //Multipart 这种是支持文件的表单请求
    @POST("/user/login?")
    Observable<UserLogin> postLoginRequest(@Field("username") String uesrname, @Field("password") String password);


    class Factory {
        private Factory() {  }

        public static ApiService createService( ) {

            Retrofit retrofit =
                    new Retrofit.Builder().
                            baseUrl(API.BASE_URL)
                            .addConverterFactory(CustomGsonConverterFactory.create())
                            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                            .build();
            return retrofit.create(ApiService.class);
        }
    }
}
